'''
Created on 31/07/2011

@author: Digao
'''
def toInt(arg):
    return int(arg)

def toStr(a,b):
    return str(a)+' '+str(b)

input = open('input.in')
CASES = int(input.readline())
for case in range(1,CASES+1):
    N,M = map(toInt,input.readline().strip().split())
    folders = {'/':1}
    for i in range(N):
        ff = input.readline().strip().split('/')
        actual = '/'+ff[0]
        folders[actual]=1
        for f in ff[1:]:
            actual=actual+'/'+f
            folders[actual] = 1
            
    before = len(folders)
    for i in range(M):
        ff = input.readline().strip().split('/')
        actual = '/'+ff[0]
        folders[actual]=1
        for f in ff[1:]:
            actual=actual+'/'+f
            folders[actual] = 1
    
                
            
        
    
    print 'Case #%d: %d'%(case,len(folders)-before)
    


